<template>
  <div class="step">
    <div class="step-number">{{ stepNum }}.</div>
    <div class="upload-box">
      <upload-img
        action="/api/upload?type=step"
        :imageUrl="uploadStepImg"
        @res-url="(data) => changeUrl"
      ></upload-img>
    </div>
    <el-input
      class="step-text"
      type="textarea"
      :rows="6"
      placeholder="请输入内容"
      v-model="value.describe"
    >
    </el-input>
    <i class="el-icon-error" @click="remove"></i>
  </div>
</template>

<script>
import UploadImg from "../../components/UploadImg.vue";
export default {
  components: { UploadImg },
  props: {
    stepNum: {
      type: Number,
      default: 1,
    },
    // v-model 绑定的数据，在组件中双向绑定的value，发布事件是input

    value: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      uploadStepImg: "images/step.jpg",
    };
  },
  methods: {
    changeUrl(data) {
      this.$emit("input", { ...this.value, img_url: data.resImgUrl });
    },
    // 删除一项
    remove() {
      this.$emit("remove-step", this.stepNum);
    },
  },
};
</script>

<style lang="stylus" scoped>
.step {
  display: flex;
  align-items: center;
  margin-bottom: 20px;

  .step-number {
    margin-right: 10px;
    font-size: 60px;
    font-weight: bold;
    width: 100px;
    height: 180px;
    flex: 0 0 100px;
    line-height: 145px;
    color: #999;
  }

  .upload-box {
    margin-right: 20px;
  }

  .step-text {
    margin-right: 10px;
  }

  .el-icon-error {
    font-size: 26px;
  }
}
</style>